<?php
namespace Admin\Model;
use Think\Model;
class SysModel extends Model{
	public function editDo(){
		if(!empty($_FILES['logo']['name'])){
			$pic = $this -> where(array('id'=>I('id','','intval')))->field('id,logo')->find();
			$url = './'.$pic['logo'];
			if(file_exists($url)){
				unlink($url);
			}
			$info = $this -> upFile();
			if($info['msg'] == 0){
				echo $info['info'];
			}
			if($info['msg'] == 1){
				$data['logo'] = $info['info']['logo']['savepath'].$info['info']['logo']['savename'];
			}
		}else{
			$data['logo'] = I('logo');
		}
		//$data['id'] =I('id');
		$data['name'] = I('name');
		$data['title'] = I('title');
		$data['keywords'] = I('keywords');
		$data['description'] = I('description');
		$data['url'] = I('url');
		$data['qq'] = I('qq');
		$data['foot'] = I('foot');
		$data['cont'] = I('cont');
		$data['plug'] = I('plug');
		$data['content'] = I('content');
		$data['call'] = I('call');
		$data['place'] = I('place');
		$data['email'] = I('email');
		$this ->where(array('Id'=>1)) -> data($data)->save();
		return true;
	}
	//上传
	public function upFile(){
		$upload = new \Think\Upload();                            // 实例化上传类
		$upload -> maxSize   = 3*1024*1024 ;                      // 设置附件上传大小
		$upload -> exts      = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload -> rootPath  = './';                              // 文件上传保存的根路径
		$upload -> savePath  = 'Uploads/Sys/';             // 设置附件上传目录
		$upload -> autoSub   = false;                             //自动使用子目录保存上传文件 默认为true
		$upload -> saveName  = 'uniqid';		
		// 上传文件 
		$info   =   $upload->upload();
		if(!$info) {                  		// 上传错误提示错误信息    
			$pic = array(
				'msg' => 0,
				'info' => $upload->getError(),
			);
		}else{								// 上传成功 获取上传文件信息 
			$pic = array(
				'msg' => 1,
				'info' => $info,		
			);
		}
		return $pic;	
	}

}